package base.test3.partition;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;


/**
 *
 *
 * 统计每一个手机号耗费的总上行流量、总下行流量、总流量
 * （1）输入数据
 *
 * （2）输入数据格式：
 * 7 	13560436666	120.196.100.99		1116		 954			200
 * id	手机号码		网络ip			上行流量  下行流量     网络状态码
 * （3）期望输出数据格式
 * 13560436666 		1116		      954 			2070
 * 手机号码		    上行流量        下行流量		总流量
 *
 *map阶段
 * 读取一行数据，切分字段
 * 抽取手机号、上行流量、下行流量
 * 以手机号为key，bean对象为value输出
 * 即context.write(手机号,bean)
 *
 *
 * reduce阶段
 * 累加上行流量和下行流量得到总流量
 */


//继承接口
public class FlowBean implements Writable {

    //上行流量
    private long upFlow;

    //下行流量
    private long downFlow;

    //总流量
    private long sumFlow;


    //提供无参构造
    public FlowBean(){

    }

    //有参构造器
    public FlowBean(long upFlow, long downFlow, long sumFlow) {
        this.upFlow = upFlow;
        this.downFlow = downFlow;
        this.sumFlow = sumFlow;
    }

    //重写toString方法
    @Override
    public String toString() {
        return upFlow + "\t" + downFlow + "\t" + sumFlow;
    }

    public long getUpFlow() {
        return upFlow;
    }

    public void setUpFlow(long upFlow) {
        this.upFlow = upFlow;
    }

    public long getDownFlow() {
        return downFlow;
    }

    public void setDownFlow(long downFlow) {
        this.downFlow = downFlow;
    }

    public long getSumFlow() {
        return sumFlow;
    }

    public void setSumFlow(long sumFlow) {
        this.sumFlow = sumFlow;
    }


    //重写序列化
    @Override
    public void write(DataOutput out) throws IOException {

        out.writeLong(upFlow);
        out.writeLong(downFlow);
        out.writeLong(sumFlow);


    }

    //重写反序列化
    @Override
    public void readFields(DataInput in) throws IOException {

        this.upFlow = in.readLong();
        this.downFlow = in.readLong();
        this.sumFlow = in.readLong();
    }
}
